package com.lzc.ai.config;

import com.lzc.ai.constants.SystemConstants;
import com.lzc.ai.repository.RedisChatMemory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lizhichuan
 * @description: TODO
 * @date 2025/5/24 23:57
 */
@Configuration
public class CommonConfiguration {


    /**
     * 指定会话记忆储存方式
     *
     * @return
     */
    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }


//    @Bean
//    public ChatClient chatClient(OpenAiChatModel model,ChatMemory chatMemory) {
//        return ChatClient
//                .builder(model)
//                .defaultSystem("你是一个热心、可爱的智能助手，能帮助用户解决各种问题，你很有礼貌，回答问题条理清晰，你的首选语言是中文。")
//                .defaultAdvisors(
//                        new SimpleLoggerAdvisor(), //配置日志Advisor
//                        new MessageChatMemoryAdvisor(chatMemory)
//                )
//                .build();
//    }


    @Bean
    public RedisChatMemory redisChatMemory() {
        return new RedisChatMemory();
    }


    @Bean
    public ChatClient chatClient(OpenAiChatModel model,RedisChatMemory redisChatMemory) {
        return ChatClient
                .builder(model)
                .defaultSystem("你是一个热心、可爱的智能助手，能帮助用户解决各种问题，你很有礼貌，回答问题条理清晰，你的首选语言是中文。")
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(), //配置日志Advisor
                        new MessageChatMemoryAdvisor(redisChatMemory) //指定会话记忆存储方式
                )
                .build();
    }


    @Bean
    public ChatClient gameChatClient(OpenAiChatModel model, ChatMemory chatMemory) {
        return ChatClient
                .builder(model)
                .defaultSystem(SystemConstants.GAME_SYSTEM_PROMPT)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory)
                )
                .build();
    }


}
